package com.david.course_design.shopping_center.module.goods.goodsDetail.controller;

import com.david.course_design.shopping_center.module.goods.goodsDetail.entity.GoodsDetail;
import com.david.course_design.shopping_center.module.goods.goodsDetail.service.GoodsDetailService;
import com.david.course_design.shopping_center.result.PageObject;
import com.david.course_design.shopping_center.result.ResultBody;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@ResponseBody
@Api(tags = "商品详情接口")
@RequestMapping("Goods/GoodsDetail/")
public class GoodsDetailController {
    // 依赖注入 dependency injection
    @Resource
    private GoodsDetailService goodsDetailService;

    @GetMapping("selectGoodsDetailPaging")
    @ApiOperation("查询商品详细信息(分页)")
    private ResultBody selectGoodsDetailPaging(PageObject pageObject) {
        PageInfo<GoodsDetail> goodsDetailPageInfo = goodsDetailService.selectGoodsDetailPaging(pageObject);
        if (goodsDetailPageInfo != null) {
            return ResultBody.success(goodsDetailPageInfo);
        } else {
            return ResultBody.error("", "没有找到数据!");
        }

    }

    @GetMapping("selectAllGoodsDetail")
    @ApiOperation("查询所有商品详细信息(不分页)")
    private ResultBody selectAllGoodsDetail() {
        List<GoodsDetail> goodsDetails = goodsDetailService.selectAllGoodsDetail();
        if (goodsDetails != null) {
            return ResultBody.success(goodsDetails);
        } else {
            return ResultBody.error("", "没有找到数据!");
        }

    }

    @GetMapping("selectGoodsDetailById")
    @ApiOperation("通过主键查询商品详细信息")
    private ResultBody selectGoodsDetailById(Integer id) {

        GoodsDetail goodsDetail = goodsDetailService.selectGoodsDetailById(id);

        if (goodsDetail != null) {
            return ResultBody.success(goodsDetail);
        } else {
            return ResultBody.error("", "没有找到数据!");
        }
    }

}
